<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <!-- <link rel="stylesheet" href="style.css"> -->
  <style>
    :root{
      --spacing:20px;
      --blur:3px;
      --base:#FFC600;
    }
    html{
      margin: 0;
      padding: 0;
    }
    body{
      background: #193549;
      font-weight: 100;
      font-size: 40px;
      font-family: serif;
      text-align: center;
      color: white;
    }
    span.hl{
      color: var(--base);
    }
    .controls{
      margin-bottom: 50px;
    }
    label{
      user-select: none;
      margin-right: 20px;
    }
    input{
      width: 100px;
      vertical-align: middle;
      margin-right: 20px;
    }
    .wrap{
      margin: 5px auto;
      display: inline-block;
    }
    .img-wrap{
      background-color: var(--base);
    }
    img{
      filter: blur(var(--blur));
      display: block;
      max-width: calc(100% - var(--spacing)*2);
      margin: var(--spacing);
    }
  </style>
</head>
<body>
  <h2>Update <span class="hl">CSS</span> Variables with <span class="hl">JS</span></h2>
  <div class="controls">
    <div class="wrap"><label for="spacing">Spacing: </label><input min="20" value="20" max="180" id="spacing" type="range" data-sizing="px"></div>
    <div class="wrap"><label for="blur">Blur: </label><input id="blur" value="0" min="0" max="25" type="range" data-sizing="px"></div>
    <div class="wrap"><label for="bace">Base Color: </label><input id="base" type="color"></div>
  </div>
  <div class="wrap img-wrap">
    <img src="https://source.unsplash.com/7bwQXzbF6KE/800x500" alt="" srcset="">
  </div>
  <script>
    (function(){
      const elms = document.querySelectorAll('.controls input')
      
      function handleEvent (e) {
        const type = e.target.id,
              val = e.target.value,
              suffix = e.target.dataset.sizing || '';
        console.log(type,val,suffix);
        //设置属性
        document.documentElement.style.setProperty(`--${type}`,`${val + suffix}`)
      }
      //设置事件监听
      elms.forEach(elm=>{
        elm.addEventListener('change',handleEvent);
        elm.addEventListener('mousemove',handleEvent);
      })
    })();
  </script>
  <!-- <script src="index.js"></script> -->
</body>
</html>